package View;

import Hander.EnrollViewHander;
import Hander.OptionChangeHander;
import entity.AdminDo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EnrollView extends JFrame {

    SpringLayout springLayout=new SpringLayout();//弹簧布局
    JPanel jPanel=new JPanel(new FlowLayout(FlowLayout.CENTER,10,20));
    public JRadioButton option1RadioButton;
    public JRadioButton option2RadioButton;
    public JRadioButton option3RadioButton;

    JLabel userNameLable=new JLabel("用户名:",JLabel.RIGHT);
    JTextField userNameTex= new JTextField();
    JLabel mimaLable=new JLabel("密码:",JLabel.RIGHT);
    JTextField mimaTex=new JTextField();
    JLabel enrollLable=new JLabel("用户类型:",JLabel.RIGHT);
    JTextField enrollTex=new JTextField();
    JButton enrollBtn=new JButton("注册");
    EnrollViewHander enrollViewHander;
    AdminDo adminDo=new AdminDo();
    OptionChangeHander optionChangeHander;
    public EnrollView(){
        super("注册");

        optionChangeHander=new OptionChangeHander(this);
        enrollViewHander=new EnrollViewHander(this );

        userNameLable.setPreferredSize(new Dimension(80,20));
        jPanel.add(userNameLable);

        userNameTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(userNameTex);

        mimaLable.setPreferredSize(new Dimension(80,20));
        jPanel.add(mimaLable);
        mimaTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(mimaTex);

        enrollLable.setPreferredSize(new Dimension(80,20));
        jPanel.add(enrollLable);
        enrollTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(enrollTex);
        enrollTex.setVisible(false);
        enrollBtn.addActionListener(enrollViewHander);
        setOptions();
        jPanel.add(enrollBtn);
        Container contentPane=  getContentPane();
        contentPane.add(jPanel);
        setSize(400,300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }
    public AdminDo buildmanger(){
        adminDo.setUserName(userNameTex.getText());
        adminDo.setPwd((mimaTex.getText()));
        adminDo.setUserType(optionChangeHander.getAdminDo().getUserType());
        return adminDo;
    }

    public static void main(String[] args) {

        new EnrollView();
    }
    public void setOptions(){
        option1RadioButton = new JRadioButton("Personnel");
        option1RadioButton.setBounds(50, 50, 100, 30);
        option2RadioButton = new JRadioButton("DepartmentHead");
        option2RadioButton.setBounds(150, 50, 100, 30);
        option3RadioButton = new JRadioButton("ProjectLeader");
        option3RadioButton.setBounds(250, 50, 100, 30);
        // 创建按钮组，将选项按钮添加到同一按钮组中
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(option1RadioButton);
        buttonGroup.add(option2RadioButton);
        buttonGroup.add(option3RadioButton);
        // 添加事件监听器
        option1RadioButton.addActionListener(optionChangeHander);
        option2RadioButton.addActionListener(optionChangeHander);
        option3RadioButton.addActionListener(optionChangeHander);
        // 将选项按钮添加到 JFrame
        jPanel.add(option1RadioButton);
        jPanel.add(option2RadioButton);
        jPanel.add(option3RadioButton);
    }

}
